package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.ShangHaiPaiHang;

public class BossAdapter extends BaseAdapter {
    ShangHaiPaiHang shangHaiPaiHang;
    Context context;

    public BossAdapter(Context context) {
        this.context = context;
    }

    public ShangHaiPaiHang getShangHaiPaiHang() {
        return shangHaiPaiHang;
    }

    public void setShangHaiPaiHang(ShangHaiPaiHang shangHaiPaiHang) {
        this.shangHaiPaiHang = shangHaiPaiHang;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return shangHaiPaiHang.getSHPaiHang().size();
    }

    @Override
    public Object getItem(int i) {
        return shangHaiPaiHang.getSHPaiHang().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.adapter_boss, null);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.tvId.setText("榜" + (i + 1));
        viewHolder.tvName.setText(shangHaiPaiHang.getSHPaiHang().get(i).getName());
        if (shangHaiPaiHang.getSHPaiHang().get(i).getSh() < 10000) {
            viewHolder.tvSh.setText("伤害:" + shangHaiPaiHang.getSHPaiHang().get(i).getSh());
        } else if (shangHaiPaiHang.getSHPaiHang().get(i).getSh() < 100000000) {
            viewHolder.tvSh.setText("伤害:" + (shangHaiPaiHang.getSHPaiHang().get(i).getSh() / 10000) + "万");
        } else {
            viewHolder.tvSh.setText("伤害:" + (shangHaiPaiHang.getSHPaiHang().get(i).getSh() / 100000000) + "亿");
        }
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvId;
        public TextView tvName;
        public TextView tvSh;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvId = (TextView) rootView.findViewById(R.id.tvId);
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvSh = (TextView) rootView.findViewById(R.id.tvSh);
        }

    }
}
